using UnityEngine;

namespace UI
{
    public static class Mouse
    {
        public static bool UpdateDrag(bool dragging, Rect controlRect)
        {
            if (Event.current==null)
                return false;

            if (!dragging)
            {
                if (Event.current.type.Equals(EventType.MouseDown) && controlRect.Contains(Event.current.mousePosition))
                {
                    Event.current.Use();
                    dragging = true;
                }
            }
            else
            {
                if (Event.current.type.Equals(EventType.MouseDrag))
                    Event.current.Use();
                else if (!Input.GetMouseButton(0))
                    dragging = false;
            }
            return dragging;
        }
    }
}